import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import routers from './router/routers.js'
import store from '@/store';
import '@/api';
//引入elemtnt
import ElementUI from 'element-ui';
import './theme/index.css'
import VueResource from 'vue-resource'
import VueWechatTitle from 'vue-wechat-title';
Vue.use(VueWechatTitle);
// import './assets/icon/iconfont.css '
import '../src/assets/icon/iconfont.css'
import 'lib-flexible/flexible'
import * as echarts from 'echarts'
import * as filters from '@/assets/js/filters' // global filters
import * as constants from '@/config/constants'
import "@/assets/js/directive"; // 防重复点击

import Probability from '@/components/TableColumn/Probability.vue'
Vue.component(Probability.name, Probability);

Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]) // 插入过滤器名和对应方法
})
import Print from 'vue-print-nb'
Vue.use(Print);


Vue.use(VueResource)

Vue.use(VueRouter)
Vue.use(ElementUI)

Vue.prototype.$echarts = echarts
Vue.prototype.$constants = constants

Vue.config.productionTip = false

const router = new VueRouter({
	mode: 'hash',
	routes: routers
})



new Vue({
	el: '#app',
	router,
	render: h => h(App),
	store
})

router.beforeEach((to, from, next) => {
	const app = document.querySelector('.app-main')
  app.scrollTo({ top: 0, left: 0 })
	if (to.meta.title!= 'school') {
	    document.title = "门道学业规划平台"
	  }
	// console.log("路由拦截")
	// 通过requiresAuth判断当前路由导航是否需要登录
	if (to.matched.some(record => record.meta.requiresAuth)) {
		let token = sessionStorage.getItem('satoken');
		// console.log("token",token)
		// 若需要登录访问，检查是否为登录状态
		if (!token) {
			//提示用户登录
			ElementUI.Message.error('请先登录...');
			next({
				path: '/',
			})
		} else {
			next()
		}
	}
	if (to.matched.some(record => record.meta.expert)) {
		let token = sessionStorage.getItem('satoken')
		// console.log("token",token)
		// 若需要登录访问，检查是否为登录状态
		const user=sessionStorage.getItem("user");
		if (user!=null&&user.userType!=3) {
			//提示用户登录
			ElementUI.Message.error('暂无权限....');
			next({
				path: '/',
			})
		} else {
			next()
		}
	}
	next()
})
